import path from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import styleImport from 'vite-plugin-style-import';

const resolve = (p) => path.resolve(__dirname, p);

const proxy = {
  '/console/': {
    target: 'http://test-yy-ctcc-scrm-admin.k8s.startdtapi.com',
    changeOrigin: true,
    secure: false,
    onProxyReq: (proxyReq) => {
      proxyReq.setHeader('x-forwarded-for', '');
    },
  },
};

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    styleImport({
      libs: [{
        libraryName: 'element-plus',
        resolveComponent: (name) => `element-plus/lib/${name}`,
      }],
    }),
  ],
  base: './',
  resolve: {
    alias: {
      '@': resolve('src'),
    },
  },
  server: {
    proxy,
    port: 9529,
  },
});
